package com.yehun.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.yehun.dao.CategoryDao;
import com.yehun.entity.Category;
import com.yehun.entity.PagerEntity;
import com.yehun.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryDao categoryDao;

    @Override
    public List<Category> listAll() {
        return categoryDao.listAll();
    }

    @Override
    public PagerEntity<Category> listPager(int pageIndex, int pageSize) {
        PagerEntity<Category> pager = new PagerEntity<>();
        Page page = PageHelper.startPage(pageIndex, pageSize);
        pager.setData(categoryDao.listAll());
        pager.setTotal(page.getTotal());
        pager.setPageIndex(pageIndex);
        pager.setPageSize(pageSize);
        return pager;
    }

    @Override
    public List<Category> listFirst() {
        return categoryDao.listFirst();
    }

    @Override
    public List<Category> listNavShow() {
        return categoryDao.listNavShow();
    }

    @Override
    public List<Category> listChilds(int id) {
        return categoryDao.listChilds(id);
    }

    @Override
    public Category get(int id) {
        return categoryDao.get(id);
    }

    @Override
    public int save(Category category) {
        return categoryDao.save(category);
    }

    @Override
    public int update(Category category) {
        return categoryDao.update(category);
    }

    @Override
    public int removeLogical(int[] idArray) {
        return categoryDao.removeLogical(idArray);
    }

    @Override
    public int removePhysics(int[] idArray) {
        return categoryDao.removePhysics(idArray);
    }
}
